bitkeeper revision 1.1293.1.1 (425ed7d4ns1ECT4A2gBGlWC_vklpGQ)
authormaf46@burn.cl.cam.ac.uk <maf46@burn.cl.cam.ac.uk>
Thu, 14 Apr 2005 20:51:32 +0000 (20:51 +0000)
committermaf46@burn.cl.cam.ac.uk <maf46@burn.cl.cam.ac.uk>
Thu, 14 Apr 2005 20:51:32 +0000 (20:51 +0000)
Now booting VT-X domain with new shadow code.

Signed-off-by: michael.fetterman@cl.cam.ac.uk
xen/arch/x86/audit.c
xen/arch/x86/shadow.c
xen/arch/x86/traps.c
xen/arch/x86/vmx.c
xen/include/asm-x86/regs.h
xen/include/asm-x86/shadow.h
xen/include/asm-x86/vmx_vmcs.h

index 8df6a962bf2bdc575e3db611bc40e6353d62aaed..9c9f198cd49507229bce7b2ad7cbe56ae4c6d328 100644 (file)
@@ -35,7 +35,6 @@ static int ttot=0, ctot=0, io_mappings=0, lowmem_mappings=0;
 static int l1, l2, oos_count, page_count;
 
 #define FILE_AND_LINE 0
-//#define MFN2_TO_WATCH 0x1d8
 
 #if FILE_AND_LINE
 #define adjust(_p, _a) _adjust((_p), (_a), __FILE__, __LINE__)
@@ -55,13 +54,6 @@ int audit_adjust_pgtables(struct domain *d, int dir, int noisy)
 
     void _adjust(struct pfn_info *page, int adjtype ADJUST_EXTRA_ARGS)
     {
-#ifdef MFN2_TO_WATCH
-        if (page_to_pfn(page) == MFN2_TO_WATCH)
-        {
-            APRINTK("adjust(mfn=%p, dir=%d, adjtype=%d)",
-                    page_to_pfn(page), dir, adjtype);
-        }
-#endif
         if ( adjtype )
         {
             // adjust the type count
index 0fddfdd9a8a23d590ac51b2997509a844a3de860..94c460faa94d56c67f7d440dbf1c80d70a1cd70e 100644 (file)
@@ -68,9 +68,14 @@ shadow_promote(struct domain *d, unsigned long gpfn, unsigned long gmfn,
 
     if ( !shadow_remove_all_write_access(d, gpfn, gmfn) )
     {
-        FSH_LOG("%s: couldn't find/remove all write accesses, gpfn=%p gmfn=%p\n",
+        FSH_LOG("%s: couldn't find/remove all write accesses, gpfn=%p gmfn=%p",
                 __func__, gpfn, gmfn);
+#if 1 || defined(LIVE_DANGEROUSLY)
+        set_bit(_PGC_page_table, &page->count_info);
+        return 1;
+#endif
         return 0;
+        
     }
 
     // To convert this page to use as a page table, the writable count
@@ -288,7 +293,7 @@ alloc_shadow_page(struct domain *d,
     return smfn;
 
   fail:
-    FSH_LOG("promotion of pfn=%p mfn=%p failed!  external gnttab refs?\n",
+    FSH_LOG("promotion of pfn=%p mfn=%p failed!  external gnttab refs?",
             gpfn, gmfn);
     free_domheap_page(page);
     return 0;
@@ -311,9 +316,6 @@ free_shadow_l1_table(struct domain *d, unsigned long smfn)
     }
 
     unmap_domain_mem(pl1e);
-
-    list_add(&spage->list, &d->arch.free_shadow_frames);
-    perfc_incr(free_l1_pages);
 }
 
 static void inline
@@ -322,6 +324,8 @@ free_shadow_hl2_table(struct domain *d, unsigned long smfn)
     l1_pgentry_t *hl2 = map_domain_mem(smfn << PAGE_SHIFT);
     int i, limit;
 
+    SH_VVLOG("%s: smfn=%p freed\n", __func__, smfn);
+
 #ifdef __i386__
     if ( shadow_mode_external(d) )
         limit = L2_PAGETABLE_ENTRIES;
@@ -353,8 +357,7 @@ free_shadow_l2_table(struct domain *d, unsigned long smfn)
                 put_shadow_ref(pl2e[i] >> PAGE_SHIFT);
 
     if ( (PGT_base_page_table == PGT_l2_page_table) &&
-         shadow_mode_translate(d) &&
-         !shadow_mode_external(d) )
+         shadow_mode_translate(d) && !external )
     {
         // free the ref to the hl2
         //
@@ -373,6 +376,8 @@ void free_shadow_page(unsigned long smfn)
     unsigned long gpfn = __mfn_to_gpfn(d, gmfn);
     unsigned long type = page->u.inuse.type_info & PGT_type_mask;
 
+    SH_VVLOG("%s: free'ing smfn=%p", __func__, smfn);
+
     ASSERT( ! IS_INVALID_M2P_ENTRY(gpfn) );
 
     delete_shadow_status(d, gpfn, gmfn, type);
@@ -414,7 +419,12 @@ void free_shadow_page(unsigned long smfn)
     page->tlbflush_timestamp = 0;
     page->u.free.cpu_mask = 0;
 
-    if ( type != PGT_l1_shadow )
+    if ( type == PGT_l1_shadow )
+    {
+        list_add(&page->list, &d->arch.free_shadow_frames);
+        perfc_incr(free_l1_pages);
+    }
+    else
         free_domheap_page(page);
 }
 
@@ -510,9 +520,9 @@ static void free_out_of_sync_state(struct domain *d)
 
 static void free_shadow_pages(struct domain *d)
 {
-    int                   i, free = 0;
-    struct shadow_status *x, *n;
-    struct exec_domain   *e;
+    int                   i;
+    struct shadow_status *x;
+    struct exec_domain   *ed;
  
     /*
      * WARNING! The shadow page table must not currently be in use!
@@ -529,58 +539,81 @@ static void free_shadow_pages(struct domain *d)
 
     // second, remove any outstanding refs from ed->arch.shadow_table...
     //
-    for_each_exec_domain(d, e)
+    for_each_exec_domain(d, ed)
     {
-        if ( pagetable_val(e->arch.shadow_table) )
+        if ( pagetable_val(ed->arch.shadow_table) )
         {
-            put_shadow_ref(pagetable_val(e->arch.shadow_table) >> PAGE_SHIFT);
-            e->arch.shadow_table = mk_pagetable(0);
+            put_shadow_ref(pagetable_val(ed->arch.shadow_table) >> PAGE_SHIFT);
+            ed->arch.shadow_table = mk_pagetable(0);
+        }
+    }
+
+    // For external shadows, remove the monitor table's refs
+    //
+    if ( shadow_mode_external(d) )
+    {
+        for_each_exec_domain(d, ed)
+        {
+            l2_pgentry_t *mpl2e = ed->arch.monitor_vtable;
+            l2_pgentry_t hl2e = mpl2e[l2_table_offset(LINEAR_PT_VIRT_START)];
+            l2_pgentry_t smfn = mpl2e[l2_table_offset(SH_LINEAR_PT_VIRT_START)];
+            if ( l2_pgentry_val(hl2e) & _PAGE_PRESENT )
+            {
+                put_shadow_ref(l2_pgentry_val(hl2e) >> PAGE_SHIFT);
+                mpl2e[l2_table_offset(LINEAR_PT_VIRT_START)] = mk_l2_pgentry(0);
+            }
+            if ( l2_pgentry_val(smfn) & _PAGE_PRESENT )
+            {
+                put_shadow_ref(l2_pgentry_val(smfn) >> PAGE_SHIFT);
+                mpl2e[l2_table_offset(SH_LINEAR_PT_VIRT_START)] = mk_l2_pgentry(0);
+            }
         }
     }
 
     // Now, the only refs to shadow pages that are left are from the shadow
-    // pages themselves.  We can just free them.
+    // pages themselves.  We just unpin the pinned pages, and the rest
+    // should automatically disappear.
     //
+    // NB: Beware: each explicitly or implicit call to free_shadow_page
+    // can/will result in the hash bucket getting rewritten out from
+    // under us...  First, collect the list of pinned pages, then
+    // free them.
+    //
+#define PINNED(_x) (frame_table[_x].u.inuse.type_info & PGT_pinned)
     for ( i = 0; i < shadow_ht_buckets; i++ )
     {
+        u32 count;
+        unsigned long *mfn_list;
+
         /* Skip empty buckets. */
         x = &d->arch.shadow_ht[i];
         if ( x->gpfn_and_flags == 0 )
             continue;
 
-        /* Free the head page. */
-        free_shadow_page(x->smfn);
-
-        /* Reinitialise the head node. */
-        x->gpfn_and_flags = 0;
-        x->smfn           = 0;
-        n                 = x->next;
-        x->next           = NULL;
-
-        free++;
-
-        /* Iterate over non-head nodes. */
-        for ( x = n; x != NULL; x = n )
-        { 
-            /* Free the shadow page. */
-            free_shadow_page(x->smfn);
-
-            /* Re-initialise the chain node. */
-            x->gpfn_and_flags = 0;
-            x->smfn           = 0;
+        count = 0;
+        for ( ; x != NULL; x = x->next )
+            if ( PINNED(x->smfn) )
+                count++;
+        if ( !count )
+            continue;
 
-            /* Add to the free list. */
-            n       = x->next;
-            x->next = d->arch.shadow_ht_free;
-            d->arch.shadow_ht_free = x;
+        mfn_list = xmalloc_array(unsigned long, count);
+        count = 0;
+        for ( x = &d->arch.shadow_ht[i]; x != NULL; x = x->next )
+            if ( PINNED(x->smfn) )
+                mfn_list[count++] = x->smfn;
 
-            free++;
+        while ( count )
+        {
+            shadow_unpin(mfn_list[--count]);
         }
-
-        shadow_audit(d, 0);
+        xfree(mfn_list);
     }
+#undef PINNED
+
+    shadow_audit(d, 0);
 
-    SH_LOG("Free shadow table. Freed=%d.", free);
+    SH_LOG("Free shadow table.");
 }
 
 void shadow_mode_init(void)
@@ -622,6 +655,12 @@ static void alloc_monitor_pagetable(struct exec_domain *ed)
     mpl2e[l2_table_offset(RO_MPT_VIRT_START)] =
         mk_l2_pgentry(pagetable_val(d->arch.phys_table) | __PAGE_HYPERVISOR);
 
+    // Don't (yet) have mappings for these...
+    // Don't want to accidentally see the idle_pg_table's linear mapping.
+    //
+    mpl2e[l2_table_offset(LINEAR_PT_VIRT_START)] = mk_l2_pgentry(0);
+    mpl2e[l2_table_offset(SH_LINEAR_PT_VIRT_START)] = mk_l2_pgentry(0);
+
     ed->arch.monitor_table = mk_pagetable(mmfn << PAGE_SHIFT);
     ed->arch.monitor_vtable = mpl2e;
 }
@@ -631,7 +670,7 @@ static void alloc_monitor_pagetable(struct exec_domain *ed)
  */
 void free_monitor_pagetable(struct exec_domain *ed)
 {
-    l2_pgentry_t *mpl2e, hl2e;
+    l2_pgentry_t *mpl2e, hl2e, sl2e;
     unsigned long mfn;
 
     ASSERT( pagetable_val(ed->arch.monitor_table) );
@@ -643,11 +682,21 @@ void free_monitor_pagetable(struct exec_domain *ed)
      * First get the mfn for hl2_table by looking at monitor_table
      */
     hl2e = mpl2e[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT];
-    ASSERT(l2_pgentry_val(hl2e) & _PAGE_PRESENT);
-    mfn = l2_pgentry_val(hl2e) >> PAGE_SHIFT;
-    ASSERT(mfn);
+    if ( l2_pgentry_val(hl2e) & _PAGE_PRESENT )
+    {
+        mfn = l2_pgentry_val(hl2e) >> PAGE_SHIFT;
+        ASSERT(mfn);
+        put_shadow_ref(mfn);
+    }
+
+    sl2e = mpl2e[SH_LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT];
+    if ( l2_pgentry_val(sl2e) & _PAGE_PRESENT )
+    {
+        mfn = l2_pgentry_val(sl2e) >> PAGE_SHIFT;
+        ASSERT(mfn);
+        put_shadow_ref(mfn);
+    }
 
-    put_shadow_ref(mfn);
     unmap_domain_mem(mpl2e);
 
     /*
@@ -1253,10 +1302,11 @@ int shadow_mode_control(struct domain *d, dom0_shadow_control_t *sc)
  */
 void vmx_shadow_clear_state(struct domain *d)
 {
-    SH_VVLOG("vmx_clear_shadow_state:");
+    SH_VVLOG("%s:", __func__);
     shadow_lock(d);
     free_shadow_pages(d);
     shadow_unlock(d);
+    update_pagetables(d->exec_domain[0]);
 }
 
 unsigned long
@@ -1313,6 +1363,8 @@ shadow_hl2_table(struct domain *d, unsigned long gpfn, unsigned long gmfn,
         BUG(); /* XXX Deal gracefully with failure. */
     }
 
+    SH_VVLOG("shadow_hl2_table(gpfn=%p, gmfn=%p, smfn=%p) => %p",
+             gpfn, gmfn, smfn, hl2mfn);
     perfc_incrc(shadow_hl2_table_count);
 
     hl2 = map_domain_mem(hl2mfn << PAGE_SHIFT);
@@ -1951,9 +2003,13 @@ int shadow_remove_all_write_access(
 
     // How many outstanding writable PTEs for this page are there?
     //
-    write_refs = (frame_table[readonly_gmfn].u.inuse.type_info & PGT_count_mask);
-    if ( write_refs && (frame_table[readonly_gmfn].u.inuse.type_info & PGT_pinned) )
+    write_refs =
+        (frame_table[readonly_gmfn].u.inuse.type_info & PGT_count_mask);
+    if ( write_refs &&
+         (frame_table[readonly_gmfn].u.inuse.type_info & PGT_pinned) )
+    {
         write_refs--;
+    }
 
     if ( write_refs == 0 )
     {
@@ -1961,7 +2017,7 @@ int shadow_remove_all_write_access(
         return 1;
     }
 
-    // Before searching all the L1 page tables, check the typical culprit first.
+    // Before searching all the L1 page tables, check the typical culprit first
     //
     if ( (prediction = predict_writable_pte_page(d, readonly_gpfn)) )
     {
@@ -2001,7 +2057,7 @@ int shadow_remove_all_write_access(
         }
     }
 
-    FSH_LOG("%s: looking for %d refs, found %d refs\n",
+    FSH_LOG("%s: looking for %d refs, found %d refs",
             __func__, write_refs, found);
 
     return 0;
@@ -2215,6 +2271,14 @@ static int resync_all(struct domain *d, u32 stype)
         {
             perfc_incrc(unshadow_l2_count);
             shadow_unpin(smfn);
+            if ( unlikely(shadow_mode_external(d)) )
+            {
+                unsigned long hl2mfn;
+
+                if ( (hl2mfn = __shadow_status(d, entry->gpfn, PGT_hl2_shadow)) &&
+                     (frame_table[hl2mfn].u.inuse.type_info & PGT_pinned) )
+                    shadow_unpin(hl2mfn);
+            }
         }
     }
 
@@ -2398,14 +2462,14 @@ int shadow_fault(unsigned long va, struct xen_regs *regs)
  * SHADOW MODE:      none         enable         translate         external
  * 
  * 4KB things:
- * guest_vtable    lin_l2     mapped per gpdt  lin_l2 via hl2   mapped per gpdt
- * shadow_vtable     n/a         sh_lin_l2       sh_lin_l2      mapped per gpdt
- * hl2_vtable        n/a            n/a        lin_hl2 via hl2  mapped per gpdt
+ * guest_vtable    lin_l2     mapped per gl2   lin_l2 via hl2   mapped per gl2
+ * shadow_vtable     n/a         sh_lin_l2       sh_lin_l2      mapped per gl2
+ * hl2_vtable        n/a            n/a        lin_hl2 via hl2  mapped per gl2
  * monitor_vtable    n/a            n/a             n/a           mapped once
  *
  * 4MB things:
- * guest_linear  lin via gpdt   lin via gpdt     lin via hl2      lin via hl2
- * shadow_linear     n/a      sh_lin via spdt  sh_lin via spdt  sh_lin via spdt
+ * guest_linear  lin via gl2    lin via gl2      lin via hl2      lin via hl2
+ * shadow_linear     n/a      sh_lin via sl2   sh_lin via sl2   sh_lin via sl2
  * monitor_linear    n/a            n/a             n/a              ???
  * perdomain      perdomain      perdomain       perdomain        perdomain
  * R/O M2P         R/O M2P        R/O M2P           n/a              n/a
@@ -2477,9 +2541,6 @@ void __update_pagetables(struct exec_domain *ed)
     {
         if ( unlikely(!(hl2mfn = __shadow_status(d, gpfn, PGT_hl2_shadow))) )
             hl2mfn = shadow_hl2_table(d, gpfn, gmfn, smfn);
-        if ( !get_shadow_ref(hl2mfn) )
-            BUG();
-
         if ( ed->arch.hl2_vtable )
             unmap_domain_mem(ed->arch.hl2_vtable);
         ed->arch.hl2_vtable = map_domain_mem(hl2mfn << PAGE_SHIFT);
@@ -2491,16 +2552,24 @@ void __update_pagetables(struct exec_domain *ed)
     if ( max_mode == SHM_external )
     {
         l2_pgentry_t *mpl2e = ed->arch.monitor_vtable;
+        l2_pgentry_t old_hl2e = mpl2e[l2_table_offset(LINEAR_PT_VIRT_START)];
+        l2_pgentry_t old_sl2e = mpl2e[l2_table_offset(SH_LINEAR_PT_VIRT_START)];
 
         ASSERT( shadow_mode_translate(d) );
 
-        BUG(); // ref counts for hl2mfn and smfn need to be maintained!
-
+        if ( !get_shadow_ref(hl2mfn) )
+            BUG();
         mpl2e[l2_table_offset(LINEAR_PT_VIRT_START)] =
             mk_l2_pgentry((hl2mfn << PAGE_SHIFT) | __PAGE_HYPERVISOR);
+        if ( l2_pgentry_val(old_hl2e) & _PAGE_PRESENT )
+            put_shadow_ref(l2_pgentry_val(old_hl2e) >> PAGE_SHIFT);
 
+        if ( !get_shadow_ref(smfn) )
+            BUG();
         mpl2e[l2_table_offset(SH_LINEAR_PT_VIRT_START)] =
             mk_l2_pgentry((smfn << PAGE_SHIFT) | __PAGE_HYPERVISOR);
+        if ( l2_pgentry_val(old_sl2e) & _PAGE_PRESENT )
+            put_shadow_ref(l2_pgentry_val(old_sl2e) >> PAGE_SHIFT);
 
         // XXX - maybe this can be optimized somewhat??
         local_flush_tlb();
@@ -2769,7 +2838,6 @@ int _check_pagetable(struct exec_domain *ed, char *s)
     if ( !(smfn = __shadow_status(d, ptbase_pfn, PGT_base_page_table)) )
     {
         printk("%s-PT %p not shadowed\n", s, gptbase);
-        errors++;
         goto out;
     }
     if ( page_out_of_sync(pfn_to_page(ptbase_mfn)) )
index 9c2b5cff75f4baa570e81cee2af3786a8cf90062..97d206ccd310ea4c3aeffef6d87f49da44c20c6c 100644 (file)
@@ -297,7 +297,8 @@ asmlinkage int do_page_fault(struct xen_regs *regs)
     }
 
     if ( unlikely(shadow_mode_enabled(d)) &&
-         ((addr < HYPERVISOR_VIRT_START) || shadow_mode_external(d)) &&
+         ((addr < HYPERVISOR_VIRT_START) ||
+          (shadow_mode_external(d) && GUEST_CONTEXT(ed, regs))) &&
          shadow_fault(addr, regs) )
     {
         return EXCRET_fault_fixed;
index a8821425cda2a1dedda70573d2cb59094ecc3d36..8093bd0c3f210d7359f58ddfad0e46552c840781 100644 (file)
@@ -521,9 +521,8 @@ static int mov_to_cr(int gp, int cr, struct xen_regs *regs)
                 domain_crash_synchronous(); /* need to take a clean path */
             }
             mfn = phys_to_machine_mapping(value >> PAGE_SHIFT);
-            vmx_shadow_clear_state(d->domain);
             d->arch.guest_table  = mk_pagetable(mfn << PAGE_SHIFT);
-            update_pagetables(d); 
+            update_pagetables(d);
             /* 
              * arch.shadow_table should now hold the next CR3 for shadow
              */
index 2f7528f327add4e871565df97a7ffbd932f655c0..5d99125d6cd2f43d56f8d2df9761ab66c1d5208d 100644 (file)
@@ -33,4 +33,10 @@ enum EFLAGS {
 
 #define GUEST_MODE(_r) (likely(VM86_MODE(_r) || !RING_0(_r)))
 
+#ifdef CONFIG_VMX
+#define GUEST_CONTEXT(_ed, _r) ( (VMX_DOMAIN(_ed) && ((_r)->eflags == 0)) || GUEST_MODE(_r) )
+#else
+#define GUEST_CONTEXT(_ed, _r) GUEST_MODE(_r)
+#endif
+
 #endif /* __X86_REGS_H__ */
index 97c40072fe6f57be219c96ea7f2a3a2c306d8f7a..0874bfc6403cf9213f71edf3da6307f3dd72482e 100644 (file)
@@ -270,20 +270,21 @@ extern int shadow_status_noswap;
 static inline int
 shadow_get_page_from_l1e(l1_pgentry_t l1e, struct domain *d)
 {
-    int res = get_page_from_l1e(l1e, d);
+    l1_pgentry_t nl1e = mk_l1_pgentry(l1_pgentry_val(l1e) & ~_PAGE_GLOBAL);
+    int res = get_page_from_l1e(nl1e, d);
     unsigned long mfn;
     struct domain *owner;
 
-    ASSERT( l1_pgentry_val(l1e) & _PAGE_PRESENT );
+    ASSERT( l1_pgentry_val(nl1e) & _PAGE_PRESENT );
 
     if ( unlikely(!res) && IS_PRIV(d) && !shadow_mode_translate(d) &&
-         !(l1_pgentry_val(l1e) & L1_DISALLOW_MASK) &&
-         (mfn = l1_pgentry_to_pfn(l1e)) &&
+         !(l1_pgentry_val(nl1e) & L1_DISALLOW_MASK) &&
+         (mfn = l1_pgentry_to_pfn(nl1e)) &&
          pfn_is_ram(mfn) &&
-         (owner = page_get_owner(pfn_to_page(l1_pgentry_to_pfn(l1e)))) &&
+         (owner = page_get_owner(pfn_to_page(l1_pgentry_to_pfn(nl1e)))) &&
          (d != owner) )
     {
-        res = get_page_from_l1e(l1e, owner);
+        res = get_page_from_l1e(nl1e, owner);
         printk("tried to map mfn %p from domain %d into shadow page tables "
                "of domain %d; %s\n",
                mfn, owner->id, d->id, res ? "success" : "failed");
@@ -292,7 +293,7 @@ shadow_get_page_from_l1e(l1_pgentry_t l1e, struct domain *d)
     if ( unlikely(!res) )
     {
         perfc_incrc(shadow_get_page_fail);
-        FSH_LOG("%s failed to get ref l1e=%p\n", __func__, l1_pgentry_val(l1e));
+        FSH_LOG("%s failed to get ref l1e=%p", __func__, l1_pgentry_val(l1e));
     }
 
     return res;
@@ -417,36 +418,11 @@ static inline void shadow_sync_and_drop_references(
 
 /************************************************************************/
 
-//#define MFN3_TO_WATCH 0x8575
-#ifdef MFN3_TO_WATCH
-#define get_shadow_ref(__s) (                                                 \
-{                                                                             \
-    unsigned long _s = (__s);                                                 \
-    if ( _s == MFN3_TO_WATCH )                                                \
-        printk("get_shadow_ref(%x) oc=%d @ %s:%d in %s\n",                    \
-               MFN3_TO_WATCH, frame_table[_s].count_info,                     \
-               __FILE__, __LINE__, __func__);                                 \
-    _get_shadow_ref(_s);                                                      \
-})
-#define put_shadow_ref(__s) (                                                 \
-{                                                                             \
-    unsigned long _s = (__s);                                                 \
-    if ( _s == MFN3_TO_WATCH )                                                \
-        printk("put_shadow_ref(%x) oc=%d @ %s:%d in %s\n",                    \
-               MFN3_TO_WATCH, frame_table[_s].count_info,                     \
-               __FILE__, __LINE__, __func__);                                 \
-    _put_shadow_ref(_s);                                                      \
-})
-#else
-#define _get_shadow_ref get_shadow_ref
-#define _put_shadow_ref put_shadow_ref
-#endif
-
 /*
  * Add another shadow reference to smfn.
  */
 static inline int
-_get_shadow_ref(unsigned long smfn)
+get_shadow_ref(unsigned long smfn)
 {
     u32 x, nx;
 
@@ -475,7 +451,7 @@ extern void free_shadow_page(unsigned long smfn);
  * Drop a shadow reference to smfn.
  */
 static inline void
-_put_shadow_ref(unsigned long smfn)
+put_shadow_ref(unsigned long smfn)
 {
     u32 x, nx;
 
@@ -486,7 +462,8 @@ _put_shadow_ref(unsigned long smfn)
 
     if ( unlikely(x == 0) )
     {
-        printk("put_shadow_ref underflow, oc=%p t=%p\n",
+        printk("put_shadow_ref underflow, smfn=%p oc=%p t=%p\n",
+               smfn,
                frame_table[smfn].count_info,
                frame_table[smfn].u.inuse.type_info);
         BUG();
@@ -508,13 +485,15 @@ shadow_pin(unsigned long smfn)
     ASSERT( !(frame_table[smfn].u.inuse.type_info & PGT_pinned) );
 
     frame_table[smfn].u.inuse.type_info |= PGT_pinned;
-    if ( !get_shadow_ref(smfn) )
+    if ( unlikely(!get_shadow_ref(smfn)) )
         BUG();
 }
 
 static inline void
 shadow_unpin(unsigned long smfn)
 {
+    ASSERT( (frame_table[smfn].u.inuse.type_info & PGT_pinned) );
+
     frame_table[smfn].u.inuse.type_info &= ~PGT_pinned;
     put_shadow_ref(smfn);
 }
@@ -767,7 +746,7 @@ validate_pte_change(
     perfc_incrc(validate_pte_calls);
 
 #if 0
-    FSH_LOG("validate_pte(old=%p new=%p)\n", old_pte, new_pte);
+    FSH_LOG("validate_pte(old=%p new=%p)", old_pte, new_pte);
 #endif
 
     old_spte = *shadow_pte_p;
@@ -1457,7 +1436,7 @@ static inline unsigned long gva_to_gpte(unsigned long gva)
     if ( unlikely(__get_user(gpte, (unsigned long *)
                              &linear_pg_table[gva >> PAGE_SHIFT])) )
     {
-        FSH_LOG("gva_to_gpte got a fault on gva=%p\n", gva);
+        FSH_LOG("gva_to_gpte got a fault on gva=%p", gva);
         return 0;
     }
 
index c9ee1cba2d62eccd6198ec9981fd361a40dfae79..80e6f7ad9c6c788c9aead4670a31f0c6a6120580 100644 (file)
@@ -59,7 +59,7 @@ struct arch_vmx_struct {
 #define vmx_schedule_tail(next)         \
     (next)->thread.arch_vmx.arch_vmx_schedule_tail((next))
 
-#define VMX_DOMAIN(d)   d->arch.arch_vmx.flags
+#define VMX_DOMAIN(ed)   ((ed)->arch.arch_vmx.flags)
 
 #define ARCH_VMX_VMCS_LOADED    0       /* VMCS has been loaded and active */
 #define ARCH_VMX_VMCS_LAUNCH    1       /* Needs VMCS launch */